package com.cat.dynamicPlanning02;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/longest-arithmetic-subsequence/
 * @create 2025/9/30 15:52
 * @since JDK17
 */

public class Solution10 {
    public int longestArithSeqLength(int[] nums) {
        int ans = 1, n = nums.length, max = Arrays.stream(nums).max().getAsInt();
        int[] dp = new int[max + 1];
        for (int d = -max; d <= max; d++) {
            Arrays.fill(dp, 0);
            for (int num : nums) {  //
                int x = num - d;
                dp[num] = x >= 0 && x <= max ? dp[x] + 1 : 1;
                ans = Math.max(ans, dp[num]);
            }
        }

        return ans;
    }
}
